package com.ssm.helong.shop.controller;


import com.alibaba.excel.metadata.Sheet;
import com.ssm.helong.shop.common.ServiceResultEnum;
import com.ssm.helong.shop.entity.GoodsCategory;
import com.ssm.helong.shop.pojo.ExportComeInsureInfo;
import com.ssm.helong.shop.service.GoodsCategoryService;

import com.ssm.helong.shop.util.Result;
import com.ssm.helong.shop.util.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.util.List;
import java.util.Objects;

@Controller
@ResponseBody
@RequestMapping("/Category")
public class GoodsCategoryController {
    @Autowired
    private GoodsCategoryService goodsCategoryService;

    /**
     * 添加
     */
    @RequestMapping(value = "/addGoodsCategory")
    public Result addGoodsCategory(@RequestBody GoodsCategory goodsCategory) {
        if (Objects.isNull(goodsCategory.getCategoryLevel())
                || StringUtils.isEmpty(goodsCategory.getCategoryName())
                || Objects.isNull(goodsCategory.getParentId())
                || Objects.isNull(goodsCategory.getCategoryRank())) {
            return ResultGenerator.genFailResult("参数异常！");
        }
        String result = goodsCategoryService.addCategory(goodsCategory);
        if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {
            return ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator.genFailResult(result);
        }
    }

    /**
     * 修改
     * @param goodsCategory
     * @return
     */
    @RequestMapping(value = "/updateGoodsCategory", method = RequestMethod.POST)
    public Result updateGoodsCategory(@RequestBody GoodsCategory goodsCategory) {
        String result = goodsCategoryService.updateGoodsCategory(goodsCategory);
        if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {
            return ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator.genFailResult(result);
        }
    }

}
